package com.gxc.exception;

import com.gxc.utils.RestControllerResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局异常处理器.
 *
 * @author 宫新程
 * @since 2018/12/6 9:27 AM
 */
@ControllerAdvice(annotations = {RestController.class, Controller.class})
@ResponseBody
public class MyExceptionHandler {

  /** 异常处理. */
  //@ExceptionHandler
  @ResponseStatus
  public RestControllerResult<Boolean> runtimeExceptionHandler(Exception e) {
    RestControllerResult<Boolean> result = new RestControllerResult<>();
    result.setSuccess(false);
    result.setErrorMsg(e.getMessage());
    return result;
  }
}
